# -*- coding: utf-8 -*-
"""后台蓝图"""
from flask import Blueprint
from flask import redirect
from flask import request
from flask import session
from flask import url_for

admin_blue = Blueprint('admin', __name__, url_prefix='/admin')
from . import views


# 添加勾子函数，作后台资源的访问权限限定
@admin_blue.before_request
def check_admin():
    is_admin = session.get('is_admin')
    # 后台只允许管理员访问，非管理员只能访问管理员登陆界面
    if not is_admin and not request.url.endswith(url_for('admin.login')):
        return redirect('/')
